// exportToExcel.ts
import * as XLSX from 'xlsx';

export const exportDataToExcel = (data: any[], fileName: string, sheetName: string = 'Sheet1') => {
  // 将数据转换为工作表
  const worksheet = XLSX.utils.json_to_sheet(data);
  // 创建一个新的工作簿并将工作表添加到其中
  const workbook = XLSX.utils.book_new();
  XLSX.utils.book_append_sheet(workbook, worksheet, sheetName);
  // 生成Excel文件并触发下载
  XLSX.writeFile(workbook, fileName);
};